﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace apitest.Application.Services
{
    public class Row
    {
        private List<Col> _cols = new List<Col>();
        public Row AddCol(Col col)
        {
            if (col == null) throw new ArgumentException("Col is null");

            var notChar = "{}[]:;\",.|\\~!@#$%^&*()+=-";
            if (string.IsNullOrEmpty(col.Name)) throw new ArgumentNullException("name");
            foreach (var c in notChar.ToCharArray())
            {
                if (col.Name.Contains(c)) throw new Exception($"名称不能包含字符:{c}");
            }

            var v = _cols.FirstOrDefault(i => i.Name == col.Name);
            if(v != null)
            {
                v.Name = col.Name;
                v.Value = col.Value;
            }
            else
            {
                _cols.Add(col);
            }
            return this;
        }
        public List<Col> Cols => _cols;
    }
}
